package com.example.studentmanager.Controller;

import com.example.studentmanager.Pojo.Home;
import com.example.studentmanager.Service.impl.homeimpl;
import com.example.studentmanager.Util.Dbtool;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "homein",value = "/homein")
public class HomeIN extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");

        String homeid=req.getParameter("homeid");

        String price=req.getParameter("price");
        int bedid= Integer.parseInt(req.getParameter("bedid"));

                Home h=new Home();
                h.setHomeid(homeid);
                h.setPrice(price);
                h.setBedid(bedid);
                homeimpl hh=new homeimpl();
                int r= hh.InsertHome(h);
                if (r>0){
                    HttpSession session = req.getSession();
                    String admin="admin";
                    String password="123456";
                    session.setAttribute("user",admin);
                    session.setAttribute("password",password);

                    req.getRequestDispatcher("home").forward(req,res);
                }else {
                    req.setAttribute("error","/home");
                    RequestDispatcher ds= req.getRequestDispatcher("./404.jsp");
                    ds.forward(req,res);
                }
            }


    }

